// const request = new Fly();
const request = function (options) {
	
	if (uni.getStorageSync("token")) {
	  let list = [
	    "/panzhihua/jsp/commons/selectDictOptionsList.do",
	    "/panzhihua/jsp/xjgl/insertGz.do",
	    "/panzhihua/jsp/xjgl/xjgd/updateBatchSuccessXjgdRw.do",
	    "/panzhihua/jsp/yjsj/insertYjsj.do",
	    "panzhihua/jsp/zhgl/insertClglPcgl.do",
	    "panzhihua/jsp/zhgl/updateClglPcgl.do",
	  ];
	  options.headers = {
	    "content-type":
	      list.indexOf(options.url) > -1
	        ? "application/x-www-form-urlencoded"
	        : "application/json",
	    Authorization: "Bearer " + uni.getStorageSync("token"),
	  };
	} else {
	  options.headers = {
	    "content-type": "application/json",
	  };
	}
	if (options.url.indexOf("selectClglPcgl") < 0) {
	  let urls = [
	    "/panzhihua/jsp/Yjya/selectYjya.do",
	    "/panzhihua/jsp/xjgl/insertGdgj.do",
	    "/panzhihua/jsp/xjgl/xjgd/selectXjgd.do",
	    "/panzhihua/jsp/app/version/selectLatestVersion.do",
	  ];
	  if (urls.indexOf(options.url) < 0) {
	    uni.showLoading({
	      mask: true,
	    });
	  }
	}
	
	const methods={
		'get':"GET",
		'post':"Post",
	}
  return new Promise((resolve, reject) => {
    uni.request({
      url: options.baseURL+options.url, // 服务器url
      method: methods[options.method] || 'GET', // 请求方法，默认为GET
      data: options.body || {}, // 请求参数
      header: options.headers || {}, // 设置请求的 header
	  sslVerify:false,
      success: (res) => {
		  console.log(res);
		  uni.hideLoading();
        // 请求成功
        if (res.statusCode === 200) {
			 resolve(res.data);
        } else {
          // 可以在这里处理非200状态码的情况
          reject(res.data);
        }
      },
      fail: (err) => {
        // 请求失败处理
        reject(err.data);
      },
    });
  });
}
export default request;

